#ifndef __SQLITE_SQL_TABLE_INFO_H_
#define __SQLITE_SQL_TABLE_INFO_H_

#include <list>
#include <string>
#include <assert.h>
#include "extension-base-func.h"
#include "extension-base-class.h"

typedef enum
{
    SQL_DATA_TYPE_INT = 1,
    SQL_DATA_TYPE_BIG_INT,
    SQL_DATA_TYPE_STRING,
}SQLDataType_E;

struct sql_column_info {
    sql_column_info( const std::string &str_name, const SQLDataType_E type, const unsigned int ui_len, const bool b_key = false )
        : mstr_name( str_name )
        , me_type( type )
        , mb_primary_key( b_key )
        , mui_len( ui_len )
    {
        if( SQL_DATA_TYPE_STRING == type ){
            if( ui_len == 0 ){
                assert( 0 );
            }
        }
    }

    sql_column_info( void )
        : mstr_name( "" )
        , me_type( SQL_DATA_TYPE_INT )
        , mb_primary_key( false )
        , mui_len( 0 )
    {

    }

    std::string get_field_type_str() const
    {
        std::string str_type;
        switch ( me_type ) {
        case SQL_DATA_TYPE_INT:
        {
            str_type = "INTEGER";
            break;
        }
        case SQL_DATA_TYPE_BIG_INT:
        {
            str_type = "BIGINT";
            break;
        }
        case SQL_DATA_TYPE_STRING:
        {
            str_type = "VARCHAR(" + convert_to_string( mui_len ) + ")";
            break;
        }
        default:
            assert( 0 );
            break;
        }

        if( !mb_primary_key ){
            str_type += " NULL";
        } else {
            str_type += " PRIMARY KEY NOT NULL";
        }

        return str_type;
    }

    std::string get_add_field_type_str() const
    {
        std::string str_type;
        switch (me_type)
        {
        case SQL_DATA_TYPE_INT:
        {
            str_type = "INTEGER";
            break;
        }
        case SQL_DATA_TYPE_STRING:
        {
            str_type = "VARCHAR(" + convert_to_string( mui_len ) + ")";
            break;
        }
        default:
            assert(0);
            break;
        }

        str_type += " NULL";

        return str_type;
    }


    std::string mstr_name;
    SQLDataType_E me_type;
    bool  mb_primary_key;
    unsigned int  mui_len;
};


struct st_sql_table_info
{
    std::string str_table_name;
    std::list<sql_column_info> col_info_list;
};

#endif
